package com.sun.lib.util;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.sun.lib.R;

/**
 * toast工具类
 *
 * @author liaoguangdong
 */
public class ToastUtil {
    private ToastUtil() {

    }

    /**
     * 弹出一个toast
     *
     * @param context
     * @param resId
     */
    public static void show(Context context, int resId) {
        //Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
        if(context == null) return;
        show(context,context.getString(resId));
    }

    /**
     * 弹出一个toast
     *
     * @param context
     * @param message
     */
    public static void show(Context context, String message) {
        if (TextUtils.isEmpty(message) || context == null) {
            return;
        }
        Toast mToast = Toast.makeText(context,"", Toast.LENGTH_SHORT);
        /*View view = LayoutInflater.from(context).inflate(R.layout.toast_view, null);
        TextView tvMessage =  view.findViewById(R.id.tv_message_toast);
        tvMessage.setText(message);
        mToast.setView(view);*/
        mToast.setDuration(Toast.LENGTH_SHORT);
        mToast.setText(message);
        mToast.show();
        //Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }

    public static void show(Context context, String message, int loc) {
        if (TextUtils.isEmpty(message) || context == null) {
            return;
        }
        Toast toast = new Toast(context);
        toast.setGravity(loc, 0, 300);
        View view = LayoutInflater.from(context).inflate(R.layout.toast_view, null);
        TextView tvMessage = (TextView) view.findViewById(R.id.tv_message_toast);
        tvMessage.setText(message);
        toast.setView(view);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.show();
    }

}
